<template>
  <div class="min-h-[calc(100vh-120px)]">
    <el-main>
      <div class="max-w-1200px mx-auto px-20px">
        <div class="flex items-center justify-start">
          <div class="line-height-20px">当前位置：</div>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>企业中心</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <el-card
          class="rounded-8px"
          shadow="never"
        >

          <!-- 服务类型 Tab -->
          <!-- <div class="mb-20px">
              <el-row
                class="flex items-start"
              >
                <el-col :span="2">
                  <h4>服务类型</h4>
                </el-col>
                <el-col :span="22">
                  <el-tabs
                  v-model="productTypeId"
                  type="card"
                  @tab-click="productTypeChange"
                  class="custom-tabs flex-1"
                >
                  <el-tab-pane
                    label="不限"
                    name="-"
                  ></el-tab-pane>
                  <el-tab-pane
                    v-for="(value,index) in industrys"
                    :key="index"
                    :label="value.typeName"
                    :name="value.typeId"
                  ></el-tab-pane>
                </el-tabs>
                </el-col>
              </el-row>
            </div> -->

          <!-- 行业分类 Tab -->
          <div class="mb-20px">
            <el-row
              :gutter="20"
              class="flex items-start"
            >
              <el-col :span="2">
                <h4>行业分类</h4>
              </el-col>
              <el-col :span="22">
                <el-tabs
                  v-model="productIndustryId"
                  type="card"
                  @tab-click="productIndustryChange"
                  class="custom-tabs flex-1"
                >
                  <el-tab-pane
                    label="不限"
                    name="-"
                  ></el-tab-pane>
                  <el-tab-pane
                    v-for="(value,index) in types"
                    :key="index"
                    :label="value.typeName"
                    :name="value.typeId"
                  ></el-tab-pane>
                </el-tabs>
              </el-col>
            </el-row>
          </div>

          <!-- 企业特色 Tab -->
          <div class="mb-20px">
            <el-row
              :gutter="20"
              class="flex items-start"
            >
              <el-col :span="2">
                <h4>企业特色</h4>
              </el-col>
              <el-col :span="22">
                <el-tabs
                  v-model="companyTypeId"
                  type="card"
                  @tab-click="companyTypeChange"
                  class="custom-tabs flex-1"
                >
                  <el-tab-pane
                    label="不限"
                    name="-"
                  ></el-tab-pane>
                  <el-tab-pane
                    v-for="(value,index) in features"
                    :key="index"
                    :label="value.typeName"
                    :name="value.typeId"
                  ></el-tab-pane>
                </el-tabs>
              </el-col>
            </el-row>
          </div>

          <!-- 所属区域 Tab -->
          <div class=" mb-20px">
            <el-row
              :gutter="20"
              class="flex items-start"
            >
              <el-col :span="2">
                <h4>所属区域</h4>
              </el-col>
              <el-col :span="22">
                <el-tabs
                  v-model="companyDivisionCode"
                  type="card"
                  @tab-click="companyDivisionChange"
                  class="custom-tabs flex-1"
                >
                  <el-tab-pane
                    label="不限"
                    name="-"
                  ></el-tab-pane>
                  <el-tab-pane
                    v-for="(value,index) in citys"
                    :key="index"
                    :label="value.prefecture"
                    :name="value.code"
                  ></el-tab-pane>
                </el-tabs>
              </el-col>
            </el-row>
          </div>

          <el-divider></el-divider>
          <!-- 搜索框 -->
          <div class="w-500px">
            <el-row
              :gutter="20"
              class="items-center flex"
            >
              <el-col :span="4">
                <h4 class="line-height-40px m-0">关键字</h4>
              </el-col>
              <el-col :span="16">
                <el-input
                  v-model="searchKeyword"
                  placeholder="请输入关键字"
                  clearable
                  @keyup.enter.native="getListData"
                ></el-input>
              </el-col>
              <el-col :span="4">
                <el-button
                  type="primary"
                  @click="getListData"
                  class="ml-10px"
                >
                  搜索
                </el-button>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <div class="mt-20px">
          <div class="suppliers">
            <el-row :gutter="20">
              <el-col
                :span="12"
                v-for="supplier in suppliers"
                :key="supplier.id"
              >
                <el-card
                  class="mb-20px h-200px flex flex-col box"
                  shadow="hover"
                  :body-style="{ padding: '0px' }"
                >
                  <div class="flex items-start justify-start p-30px">
                    <img
                      :src="baseUrl+'api/public/file/v1/public/get/'+supplier.companyLogo"
                      class="w-180px h-120px object-contain m-0"
                    />
                    <div class="ml-20px">
                      <div class="w-full flex-shrink-0 text-[#4E5969]">
                        <h2 class="m-0">{{ supplier.companyName }}</h2>
                      </div>
                      <p class=" m-0 mb-5px text-[#4E5969]">
                        地址：{{ supplier.companyAddress }}
                      </p>
                      <div class="mt-15px">
                        <el-tag
                          v-for="(res, index) in supplier.companyTypeList"
                          :key="index"
                          :type="getRandomTagType()"
                          class="mr-10px"
                        >
                          {{ res }}
                        </el-tag>
                      </div>
                    </div>
                  </div>
                </el-card>
              </el-col>
            </el-row>
          </div>
        </div>
        <el-pagination
          background
          layout="prev, pager, next"
          :total="total"
          :page-size="pageSize"
          :current-page="currentPage"
          @current-change="handlePageChange"
          class="flex justify-end"
        ></el-pagination>
      </div>
    </el-main>
  </div>
</template>

<script>
import { getCompanyPage } from "../api/home";
import { mapGetters } from "vuex";
export default {
  name: "enterpriseCenter",
  data() {
    return {
      productTypeId: "-",
      productIndustryId: "-",
      companyTypeId: "-",
      companyDivisionCode: "-",
      searchKeyword: "",
      suppliers: [],
      total: 100,
      currentPage: 1,
      pageSize: 6,
      baseUrl: process.env.VUE_APP_BASE_API,
    };
  },
  computed: {
    ...mapGetters("dicts", ["cityDict", "getDictByParamsKey"]),
    citys() {
      return this.cityDict;
    },
    industrys() {
      return this.getDictByParamsKey({ parentId: 1 });
    },
    types() {
      return this.getDictByParamsKey({ parentId: 2 });
    },
    features() {
      return this.getDictByParamsKey({ parentId: 3 });
    },
  },
  mounted() {
    this.getListData();
  },
  methods: {
    getListData() {
      const params = {
        isAsc: true,
        pageNo: this.currentPage,
        pageNum: this.pageSize,
        q: this.searchKeyword,
      };
      if (this.productTypeId != "-") {
        params.productTypeId = this.productTypeId;
      }
      if (this.productIndustryId != "-") {
        params.productIndustryId = this.productIndustryId;
      }
      if (this.companyTypeId != "-") {
        params.companyTypeId = this.companyTypeId;
      }
      if (this.companyDivisionCode != "-") {
        params.companyDivisionCode = this.companyDivisionCode;
      }
      getCompanyPage(params).then((res) => {
        this.suppliers = res.rows;
      });
    },
    productTypeChange(e) {
      this.productTypeId = e.name;
      this.getListData();
    },
    productIndustryChange(e) {
      this.productIndustryId = e.name;
      this.getListData();
    },
    companyTypeChange(e) {
      this.companyTypeId = e.name;
      this.getListData();
    },
    companyDivisionChange(e) {
      this.companyDivisionCode = e.name;
      this.getListData();
    },
    getRandomTagType() {
      const types = ["success", "warning", "danger"];
      const randomIndex = Math.floor(Math.random() * types.length);
      return types[randomIndex];
    },
    handlePageChange(page) {
      this.currentPage = page;
      this.getListData();
    },
  },
};
</script>

<style scoped>
/* 自定义 Tabs 样式 */
.custom-tabs ::v-deep .el-tabs__header {
  margin-bottom: 0 !important;
  border-bottom: none !important;
}

.custom-tabs ::v-deep .el-tabs__nav {
  border: none !important;
  display: flex;
  flex-wrap: wrap; /* 允许换行 */
}

.custom-tabs ::v-deep .el-tabs__item {
  height: 30px !important;
  line-height: 30px !important;
  padding: 0 12px !important;
  border: none !important;
  background: transparent !important;
  border-radius: 0 !important;
  flex-shrink: 0; /* 防止压缩 */
}

.custom-tabs ::v-deep .el-tabs__item.is-active {
  background-color: #0094de !important;
  color: white !important;
  border: none !important;
}

.custom-tabs ::v-deep .el-tabs__item:not(.is-active):hover {
  color: #409eff !important;
}

.bread-box {
  display: flex;
  align-items: center;
  justify-content: start;
}

.el-breadcrumb {
  padding: 15px;
  border-radius: 4px;
}

::v-deep .el-pagination.is-background .btn-next,
::v-deep .el-pagination.is-background .btn-prev,
::v-deep .el-pagination.is-background .el-pager li {
  background-color: #fff !important;
}

::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
  color: #596df4 !important;
  border: 1px solid #596df4 !important;
}
.box {
  background-image: url("/src/assets/image/enter-bg.png");
  background-size: cover;
  background-position: center;
}
</style>